<template>
  <dialogPublic
    title="签名"
    :show.sync="showDialog"
    @doSubmit="toSign"
    @doClose="doClose"
    width="500px"
    height="200px"
  >
    <editForm :formConfig="loginFormConfig" ref="loginForm" :formData="loginForm" />
  </dialogPublic>
</template>
<script>
import { verifyStaffInfo } from "@/api/twoTicketManagement/workTicket.js";
export default {
  props: {
    showSignature: {
      type: Boolean,
      default: true
    },
    account: {
      type: String,
      default: ""
    },
    signList: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  data() {
    return {
      showDialog: true,
      loginForm: {},
      loginFormConfig: {
        // labelWidth: "140px",
        itemArr: [
          {
            label: "用户名",
            prop: "account",
            type: "text",
            span: 24,
            required: true,
            disabled: false,
            autofocus: true
          },
          {
            label: "密码",
            prop: "password",
            type: "password",
            required: true,
            span: 24
          }
        ]
      }
    };
  },
  mounted() {
    if (this.account != "") {
      this.loginFormConfig.itemArr[0].disabled = true;
      this.$set(this.loginForm, "account", this.account);
    }
  },
  methods: {
    // 确定签名
    async toSign() {
      let form = await this.$refs.loginForm.getFormData();
      let canSign = true;
      if (this.signList.length > 0) {
        canSign = !this.signList.includes(form.account);
      }
      if (canSign) {
        form.password = await this.$utils.encryptPassword(form.password);
        verifyStaffInfo(form)
          .then(res => {
            this.$emit("doSign", res.data);
            this.doClose();
          })
          .catch(e => {
            console.log(e);
          });
      } else {
        this.$message.warning("您已签名，不能重复签名!");
      }
    },
    judgeRepeat() {
      return;
    },
    doClose() {
      this.$emit("update:showSignature", false);
    }
  }
};
</script>
<style lang="less" scoped>
</style>